package com.ruoyi.framework.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * mybatisplus自定义填充
 *
 * @author DY
 */
@Slf4j
@Component
@AllArgsConstructor
public class MPMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        // System.out.println("插入方法实体填充")

        Date now = new Date();
        // setFieldValByName("createUser", 1234, metaObject);
        setFieldValByName("createTime", now, metaObject);
        // setFieldValByName("updateUser", 1234, metaObject);
        setFieldValByName("updateTime", now, metaObject);
        // 业务状态 1正常 2冻结 3停工 4。。。
        setFieldValByName("status", 1, metaObject);
        setFieldValByName("isDeleted", 0, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // System.out.println("更新方法实体填充")

        Date now = new Date();
        // setFieldValByName("updateUser", 1234, metaObject);
        setFieldValByName("updateTime", now, metaObject);
    }

}
